/* 788. 旋转数字 */
/**
 * @param {number} n
 * @return {number}
 */
/* 
    枚举每一个数
    数中没有出现3，4，7
    数中至少出现一次2或5或6或9
    对于0，1，8 则没有要求
*/
const check = [0, 0, 1, -1, -1, 1, 1, -1, 0, 1]
var rotatedDigits = function (n) {
	let ans = 0
	for (let i = 1; i <= n; ++i) {
		const num = '' + i
		let valid = true,
			diff = false
		for (let j = 0; j < num.length; j++) {
			const ch = num[j]
			if (check[ch.charCodeAt() - '0'.charCodeAt()] === -1) {
				valid = false
			} else if (check[ch.charCodeAt() - '0'.charCodeAt()] === 1) {
				diff = true
			}
		}
		if (valid && diff) ++ans
	}

	return ans
}
